import request from '@/utils/request'
import {
  createActivityRequest,
  createActivityResponse,
  getActivitiesBriefRequest,
  getActivitiesBriefResponse,
  getActivityChiefResponse,
  getActivityFilterRequest
} from '@/types/activity'
import { baseResponse } from '@/types'
import { formattingQueryActivityFilter } from '@/utils/publicMethod'

//新增一个活动
export const registerActivity = async (activity: createActivityRequest) =>
  (await request.post<baseResponse<createActivityResponse>>('VoluntaryActivity/Activity/CreateActivity', activity)).data

//获取活动简略列表
export const getActivitiesBriefList = async (activityList: getActivitiesBriefRequest) =>
  (await request.post<baseResponse<Array<getActivitiesBriefResponse>>>('VoluntaryActivity/Activity/GetActivitiesBrief', activityList)).data

//获取一个活动详情
export const getActivityChief = async (activityId: number) =>
  (await request.get<baseResponse<getActivityChiefResponse>>(`VoluntaryActivity/Activity/GetActivityChief?activityId=${activityId}`)).data
// 获取符合条件的活动
export const getFilterActivities = async (activityFilter: getActivityFilterRequest) => {
  const query = formattingQueryActivityFilter(activityFilter)
  return (await request.get<baseResponse<Array<number>>>(`VoluntaryActivity/Activity/FilterActivity?${query}`)).data
}
